package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@Api(tags = "预约设置管理开发")
public class OrderSettingController {
    // springmvc  消息转化器   @ResponseBody  默认 全字段序列化
    @Reference
   private OrderSettingService orderSettingService;

    @PostMapping("ordersetting/importOrderSettings")
    @ApiOperation(value = "读取报表文件",notes = "读取excelFile文件添加或更新到数据库")
    public Result importOrderSettings(@RequestParam("excelFile")MultipartFile file) throws IOException {
        //判断文件是否为excel文件
        POIUtils.checkFile(file);
        //  file  excel文件---  List<OrderSetting>
        List<String[]> readExcelList = POIUtils.readExcel(file);
        //  string[0]==日期   string[1]==预约数
       return new Result( orderSettingService.importOrderSettings(readExcelList));
    }

    @GetMapping("ordersetting/findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable("year")int year,@PathVariable("month")int month){
        return new Result(orderSettingService.findSettingData(year,month));
    }

    @PutMapping("ordersetting/updateNumberByOrderDate/{number}/{orderdate}")
    public Result updateNumberByOrderDate(@PathVariable("number") int number ,@PathVariable("orderdate")String orderdate){
        return new Result(orderSettingService.updateNumberByOrderDate(number,orderdate));
    }
}
